//
//  LoadingImageView.m
//  HuiWanVillage
//
//  Created by jkn on 15/9/1.
//  Copyright (c) 2015年 jkn. All rights reserved.
//

#import "LoadingImageView.h"

@interface LoadingImageView ()

@end

@implementation LoadingImageView

- (void)viewDidLoad
{
    [super viewDidLoad];
}

+(void)startAnimation
{
    
}

+(UIView *)showLoadingImageView
{
    UIWindow *window = MMKeyWindow;
    
    
    for (UIView * view in [window subviews])
    {
        
        if (view.tag == 10086)
        {
            [view removeFromSuperview];
        }
    }
    
    UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, NAVBAR_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT)];
    view.backgroundColor = [UIColor clearColor];
    view.tag = 10086;
    [window addSubview:view];
//    [window.rootViewController.view bringSubviewToFront:view];
    
    
    UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/2 - 50/2, SCREEN_HEIGHT/2 - 50/2 - NAVBAR_HEIGHT, 50, 50)];
    imageView.backgroundColor = [UIColor clearColor];
    CABasicAnimation* rotationAnimation;
    rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 ];
    rotationAnimation.duration = 1;
    rotationAnimation.cumulative = YES;
    rotationAnimation.repeatCount = MAXFLOAT;
    [imageView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];      //设置动画帧
    imageView.image = [UIImage imageNamed:@"loading4.png"];
    
    
    //    imageView.animationImages=[NSArray arrayWithObjects:
    //                               [UIImage imageNamed:@"loading8.png"],
    //                               [UIImage imageNamed:@"loading7.png"],
    //                               [UIImage imageNamed:@"loading6.png"],
    //                               [UIImage imageNamed:@"loading5.png"],
    //                               [UIImage imageNamed:@"loading4.png"],
    //                               [UIImage imageNamed:@"loading3.png"],
    //                               [UIImage imageNamed:@"loading2.png"],
    //                               [UIImage imageNamed:@"loading1.png"],
    //                               nil ];
    
    //    //设置动画总时间
    //    imageView.animationDuration=2.0;
    //
    //    //设置重复次数，0表示不重复
    //    imageView.animationRepeatCount=0;
    //
    //    //开始动画
    //    [imageView startAnimating];
    
    [view addSubview:imageView];
    
    return view;
    
}

+(void)hideLoadingImageView
{
    
    UIWindow *window = [[[UIApplication sharedApplication] windows] objectAtIndex:0];
    
    for (UIView * imageView in [window subviews])
    {
        
        if (imageView.tag == 10086)
        {
            [imageView removeFromSuperview];
            
        }
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
